package com.getpebble.android.framework.protocol.inbound;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.framework.protocol.EndpointId;
import java.nio.ByteBuffer;

public class PblInboundPhoneControlMessage extends PblInboundMessage {
    private PhoneControlAction mAction;
    private byte[] mCookie = new byte[4];

    public enum PhoneControlAction {
        UNKNOWN((byte) 0),
        HANGUP((byte) 2);
        
        private byte action;

        private PhoneControlAction(byte command) {
            this.action = command;
        }

        public static PhoneControlAction fromByte(byte b) {
            for (PhoneControlAction r : values()) {
                if (r.action == b) {
                    return r;
                }
            }
            return UNKNOWN;
        }
    }

    public PblInboundPhoneControlMessage(ProtocolMessage message) {
        super(message);
        ByteBuffer buffer = message.getDataBuffer();
        this.mAction = PhoneControlAction.fromByte(buffer.get());
        buffer.get(this.mCookie, 0, 4);
    }

    public PhoneControlAction getAction() {
        return this.mAction;
    }

    public EndpointId getId() {
        return EndpointId.PHONE_CONTROL;
    }

    protected int getMinSize() {
        return 5;
    }
}
